﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
///<summary>
///这个脚本具体实现 , 但是实际上又被MonoManager封装了一次
///</summary>
public class MonoController : MonoBehaviour
{
    private event UnityAction updateEvent; //event跟委托的区别就是event是更加封闭的委托 , 不能在类外调用和赋值
    // Start is called before the first frame update
    void Start()
    {
        DontDestroyOnLoad(this.gameObject);
    }

    // Update is called once per frame
    void Update()
    {
        if(updateEvent!=null)
        {
            updateEvent();
        }
    }
    /// <summary>
    /// 提供给外部的添加帧更新的方法
    /// </summary>
    /// <param name="unityAction">传入方法的委托</param>
    public void AddUpdateListener(UnityAction unityAction)
    {
        updateEvent += unityAction;
    }

    /// <summary>
    /// 有加就有减 , 提供给外部的移除帧更新的方法
    /// </summary>
    /// <param name="unityAction"></param>
    public void RemoveUpdateListener(UnityAction unityAction)
    {
        updateEvent -= unityAction;
    }
}
